package com.gxa.insurance.controller;

import com.gxa.insurance.pojo.Permission;
import com.gxa.insurance.service.PermissionService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wang li sha
 * @date 2022-06-06 17:58
 */
@Api(value = "权限permission相关的api接口")
@RestController
@RequestMapping("/permission")
@CrossOrigin
public class PermissionController {
    @Autowired
    PermissionService permissionService;

    @ApiOperation("查询所有权限的方法")
    @PostMapping("/selectAll")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户token", paramType = "header")
    })
    public Map selectAll(@RequestHeader(value = "token", required = false) String token) throws Exception {
        List<Permission> permissions = permissionService.selectAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(permissions);
        return jsonResult.getMap();
    }

    @ApiOperation("根据RoleId查询所有权限的方法")
    @PostMapping("/selectByRoleId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户token", paramType = "header")
    })
    public Map selectByRoleId(@RequestParam("roleId") Integer roleId, @RequestHeader(value = "token", required = false) String token) throws Exception {
        List<Permission> permissions = permissionService.selectByRoleId(roleId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(permissions);
        return jsonResult.getMap();
    }
}
